In [1]:
%load_ext sql
%sql sqlite://
Out[1]:
In [5]:
%%sql drop table if exists product;
create table product(
pname varchar primary key, -- name of the product
price money, -- price of the product
category varchar, -- category
manufacturer varchar NOT NULL -- manufacturer
);
insert into product values('Gizmo', 19.99, 'Gadgets', 'GizmoWorks');
insert into product values('PowerGizmo', 29.99, 'Gadgets', 'GizmoWorks');
insert into product values('MultiTouch', 203.99, 'Household', 'Hitachi');
insert into product values('SingleTouch', 149.99, 'Photography', 'Canon');
Out[5]:
In [6]:
%sql select * from product;
Out[6]:
Напишите запрос:
In [9]:
%%sql
PRAGMA case_sensitive_like=ON;
select * from product
where pname LIKE '%Touch'
Out[9]:
Напишите запрос, возвращающий уникальные названия компаний, которые делают продукцию Gizmo:
In [13]:
%%sql
select distinct manufacturer
from product
where pname = 'Gizmo';
Out[13]:
In [14]:
%sql SELECT DISTINCT category FROM product ORDER BY category;
Out[14]:
In [15]:
%sql SELECT category FROM product ORDER BY pname;
Out[15]:
In [16]:
%sql SELECT DISTINCT category FROM product ORDER BY pname;
Out[16]:
In [ ]:
In [ ]: